package com.ruoyi.management.base.config;


import com.aliyun.teaopenapi.models.Config;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import static com.aliyun.teautil.Common.toJSONString;


public class Sample {
    public static Client createClient() throws Exception {
        // 临时打印环境变量值，验证是否获取成功
        System.out.println("AccessKey ID: " + System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"));
        System.out.println("AccessKey Secret: " + System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        Config config = new Config()
                // 读取正确的环境变量名（和你刚才配置的变量名一致）
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));

        // 配置 Endpoint。中国站使用dysmsapi.aliyuncs.com
        config.endpoint = "dysmsapi.aliyuncs.com";

        return new Client(config);
    }

    public static void main(String[] args) throws Exception {
        // 初始化请求客户端
        Client client = Sample.createClient();

        // 构造API请求对象，请替换请求参数值
         SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers("18550896994")
                .setSignName("苏州青澜实业")  // 注意：这里的签名名称必须是在阿里云控制台已审核通过的
                .setTemplateCode("SMS_493800185") ;

        // 获取响应对象
        SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);

        // 响应包含服务端响应的 body 和 headers
        System.out.println(com.aliyun.teautil.Common.toJSONString(sendSmsResponse));
    }
}